package com.easyhome.report.tool;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.LinkedHashMap;
import java.util.Map;

public class Han_db {
	public static Map<String,String> getColumnAndType(String tableName) {
		String URL = "jdbc:mysql://10.202.0.61:3306/FINA_REPORT_BI";
		 String NAME = "fi-user";
		String PASSWORD = "Juran@503";
		
		Map<String,String> map = new LinkedHashMap<>();
		// 1.加载驱动程序
		try {
			Class.forName("com.mysql.jdbc.Driver");

			// 2.获得数据库的连接
			Connection conn = DriverManager.getConnection(URL, NAME, PASSWORD);
			// 3.通过数据库的连接操作数据库，实现增删改查
			Statement stmt = conn.createStatement();
			ResultSet rs = stmt.executeQuery("SELECT  column_name,  data_type  FROM  information_schema.COLUMNS  WHERE  table_schema = 'FINA_REPORT_BI'  AND table_name = '"+tableName+"'; ");// 选择import
			// java.sql.ResultSet;
			while (rs.next()) {// 如果对象中有数据，就会循环打印出来
				map.put(rs.getString("column_name"), rs.getString("data_type"));
		
			}

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return map;
	}
	public static Map<String,String> getColumnAndComments(String tableName) {
		String URL = "jdbc:mysql://10.202.0.61:3306/FINA_REPORT_BI";
		 String NAME = "fi-user";
		String PASSWORD = "Juran@503";
		
		Map<String,String> map = new LinkedHashMap<>();
		// 1.加载驱动程序
		try {
			Class.forName("com.mysql.jdbc.Driver");

			// 2.获得数据库的连接
			Connection conn = DriverManager.getConnection(URL, NAME, PASSWORD);
			// 3.通过数据库的连接操作数据库，实现增删改查
			Statement stmt = conn.createStatement();
			ResultSet rs = stmt.executeQuery("SELECT  column_name,  column_comment  FROM  information_schema.COLUMNS  WHERE  table_schema = 'FINA_REPORT_BI'  AND table_name = '"+tableName+"';  ");// 选择import
			// java.sql.ResultSet;
			while (rs.next()) {// 如果对象中有数据，就会循环打印出来
				map.put(rs.getString("column_name"), rs.getString("column_comment"));
		
			}

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return map;
	}
}
